
clear 
set more off

** Set directory
cd "C:\Users\14128\OneDrive - University of Pittsburgh\Research_Projects\LASA\Datos"   // here you should include your own directory

*****************************************************************
* Peru 2001-2006
*****************************************************************
{
*Calling the data 2000-2005
 import spss using  ".\Peru\BASEDATOS_PERU_31.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{

gen wave = 1 
 drop legis 
gen legis = 2006
* Ideology 
gen ID1 = p67 // 1 left 
replace ID1=. if  p67>11
* Ideology Party
gen ID2=p68 // 1 left 
replace ID2=. if  p68>11

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "PER_UnidadNacional" if partido ==1 
replace party = "PER_FIM" if partido ==2
replace party = "PER_PAP" if partido ==7
replace party = "PER_UPP" if partido ==8
replace party = "PER_PeruPosible" if partido ==11
replace party = "PER_Other" if partido ~=. & partido ~=1 & partido ~=2 & partido ~=7 & partido ~=8 & partido ~=11    

drop partido 

gen partido=party

// Attendance to church
gen church_attend=p70 
replace church_attend=. if  p70>8

gen regular=1 if p70==3 | p70==4 // mes o todos los domings
replace regular=0 if p70==1 | p70==2 // casi nunca y varias al ano
replace regular=. if p70>8  

*--------------------------
* Abortion
*--------------------------
gen val_abortion = . 
replace val_abortion =2 if p74==5
replace val_abortion =4 if p74==4
 replace val_abortion =6 if p74==3
replace val_abortion =8 if p74==2
replace val_abortion =10 if p74==1

lab define VAL21 ///
	2 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL21

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious =. 
replace religious = 1 if p69==1 | p69==2 
replace religious = 0 if p69==4 | p69==5 

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Education
*--------------------------
gen education=p76 if p76<7


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312
*--------------------------
* Gender
*--------------------------
gen female=1 if p71==2
replace female=0 if p71==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=p72 if p72<100




*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated = p34a*2 if p34a<88
lab define EMI_22 ///
	2 "State" ///
	10 "Market"
lab val eco_regulated EMI_22

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=. 
replace eco_education_u = round(1*7/4) if p3507==4
replace eco_education_u = round(2*7/4) if p3507==3
replace eco_education_u = round(3*7/4) if p3507==2
replace eco_education_u = round(4*7/4) if p3507==1
replace eco_education_u = . if p3507>7

lab define eco_education_u2 ///
	2 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u2

*-----------------------
* Price control
*-----------------------
gen eco_prices=. 
replace eco_prices = round(1) if p3501==4
replace eco_prices = round(2) if p3501==3
replace eco_prices = round(3) if p3501==2
replace eco_prices = round(4) if p3501==1
replace eco_prices = . if p3501>7

lab define eco_prices ///
	1 "Against" ///
	4 "In Favor"
lab val eco_prices eco_prices

*-----------------------
* Free education primary
*-----------------------
gen eco_education_p=. 
replace eco_education_p = round(1) if p3502==4
replace eco_education_p = round(2) if p3502==3
replace eco_education_p = round(3) if p3502==2
replace eco_education_p = round(4) if p3502==1
lab val eco_education_p eco_prices
replace eco_education_p = . if p3502>7

*-----------------------
* Free education secondary
*-----------------------
gen eco_education_s=. 
replace eco_education_s = round(1) if p3505==4
replace eco_education_s = round(2) if p3505==3
replace eco_education_s = round(3) if p3505==2
replace eco_education_s = round(4) if p3505==1
lab val eco_education_s eco_prices
replace eco_education_s = . if p3505>7

*-----------------------
* Subside to housing
*-----------------------
gen eco_housing=. 
replace eco_housing = round(1) if p3503==4
replace eco_housing = round(2) if p3503==3
replace eco_housing = round(3) if p3503==2
replace eco_housing = round(4) if p3503==1
lab val eco_housing eco_prices
replace eco_housing = . if p3503>7

*-----------------------
* Employment
*-----------------------
gen eco_employment=. 
replace eco_employment = round(1*7/4) if p3504==4
replace eco_employment = round(2*7/4) if p3504==3
replace eco_employment = round(3*7/4) if p3504==2
replace eco_employment = round(4*7/4) if p3504==1

lab val eco_employment eco_education_u2
replace eco_employment = . if p3504>7

*-----------------------
* Unemployment
*-----------------------
gen eco_unemployment=. 
replace eco_unemployment = round(1) if p3508==4
replace eco_unemployment = round(2) if p3508==3
replace eco_unemployment = round(3) if p3508==2
replace eco_unemployment = round(4) if p3508==1

lab val eco_unemployment eco_prices
replace eco_unemployment = . if p3508>7

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=. 
replace eco_pensions = round(1*7/4) if p3506==4
replace eco_pensions = round(2*7/4) if p3506==3
replace eco_pensions = round(3*7/4) if p3506==2
replace eco_pensions = round(4*7/4) if p3506==1

lab val eco_pensions eco_education_u2
replace eco_pensions = . if p3506>7

*-----------------------
* Environment
*-----------------------
gen eco_environment=. 
replace eco_environment = round(1) if p3508==4
replace eco_environment = round(2) if p3508==3
replace eco_environment = round(3) if p3508==2
replace eco_environment = round(4) if p3508==1

lab val eco_environment eco_prices
replace eco_environment = . if p3508>7

*-----------------------
* Basic necessity
*-----------------------
gen eco_necessity =. 
replace eco_necessity  = round(1) if p3510==4
replace eco_necessity  = round(2) if p3510==3
replace eco_necessity  = round(3) if p3510==2
replace eco_necessity  = round(4) if p3510==1

lab val eco_necessity  eco_prices

replace eco_necessity = . if p3510>7

*-----------------------
* Tax
*-----------------------
gen eco_tax = p40 if p40<6
lab define taxes ///
	1 "Direct" ///
	2 "Indirect" ///
	3 "No more taxes"
lab val eco_tax taxes

*-----------------------
* Privatization
*-----------------------
gen eco_private = p42 if p42<6

lab define private ///
	1 "In favor" ///
	5 "Against"
lab val eco_private private
*-----------------------
* Religious values
*-----------------------
gen val_religious = p70b*2 if p70b<6
lab define secu ///
	1 "Christian" ///
	10 "Secular"
lab val val_religious secu

*-----------------------
* Divorce
*-----------------------
gen val_divorce = p73 if p73<6
replace val_divorce  = 2 if p73==5
replace val_divorce  = 4 if p73==4
replace val_divorce  = 6 if p73==3
replace val_divorce  = 8 if p73==2
replace val_divorce  = 10 if p73==1
lab define div ///
	1 "Against" ///
	10 "In Favor"
lab val val_religious secu
lab val val_divorce div

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if p69a==3
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if p69a==1
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if p69a~=3 & religious==1 &  p69a~=.  &  p69a~=1
replace rel_other=0 if religious==1 & rel_catholic==1 & rel_evangelical==1
 


}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
//lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
//lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
//lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_prices "Price control (1-4, 4 in favor of state  intervention)"
lab var eco_education_p "Free primary education  (1-4, 4 in favor of state  intervention)"
lab var eco_education_s "Free secondary education"
//lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_housing "Subsidize housing (1-4, 4 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_unemployment "Unemployment insurance  (1-4, 4 in favor)"
lab var eco_pensions "Pension  (1-7, 7 in favor)"
lab var eco_environment "(1-4, 4 in favor)"
//lab var eco_health "Whether the state should provide health services  (1, 7 in favor). "
lab var eco_necessity "(1-4, 4 in favor)"
//lab var eco_wellbeing "Whether the state should guarantee basic wellbeing  (1, 7 in favor). "
//lab var eco_companies "Whether the state should own companies  (1, 5). "
//lab var eco_services "Whether the state should  control public services  (1, 5)."
lab var eco_private "Whether the state should privatize state industries  (1 in favor, 5 against). "
//lab var eco_natural ""
lab var eco_tax "Whether legislator prefers direct or indirect taxes (1=direct, 2=indirect, 3=no more tax)"
lab var val_religious "Degree of religiosity and secularity in public policies (1 Christian, 5 secular). "
lab var val_divorce "Opinion about divorce (1 against, 10 in favor). "

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep rel_evangelical wave eco_regulated education female age eco_prices eco_education_p eco_education_s  eco_education_u eco_housing eco_employment eco_unemployment eco_pensions eco_environment  eco_necessity    eco_private  eco_tax val_religious val_divorce nestu pais partido legis ID1 ID2 church_attend religious rel_catholic rel_other val_abortion
	

}

*****************************************************************
* Save
***************************************************************** 
save "Peru_2001_2006.dta", replace
}

*****************************************************************
* Peru_2006_2011
*****************************************************************
// IMPOSSIBLE
{
clear all
import spss using ".\Peru\BASEDATOS_PERU_61.sav"



keep nestu Pais legis partido p28 p2901-p2907 p33 p35 p64 p65 p66 p66a p67 p68 p69 p70 p73


label variable nestu "Study number"
rename Pais pais
label variable pais "Country name"
label variable partido "Party name"
label variable legis "Legislature"

label drop labels0
label values pais
tostring pais, replace
replace pais="Peru"

replace legis=2011

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "PER_UnidadNacional" if partido ==3 //
replace party = "PER_APRA" if partido ==2 //
replace party = "PER_UPP" if partido ==1 //
replace party = "PER_AF" if partido ==4 //

replace party = "PER_Other" if partido >4    

drop partido 

gen partido=party


label variable p64 "Ideology"
rename p64 ID1
replace ID1 = . if ID1 > 10
label variable p65 "Ideology of your party"
rename p65 ID2
replace ID2 = . if ID2 > 10

label variable p67 "Female (dummy 1 if woman)"
rename p67 female
recode female (1=0)(2=1)
label define female_label 1 "female" 0 "male"
label value female female_label

rename p66 religious
recode religious (2=0)
replace religious=. if religious > 2
label variable religious "Religious (dummy 1 if believer)"
label define religious_label 1 "believer" 0 "nonbeliever"
label value religious religious_label

gen rel_evangelical=1 if p66a==3
replace rel_evangelical=0 if rel_evangelical!=1 & rel_evangelical!=.
label variable rel_evangelical "Evangelical (dummy 1 if evangelical)"
label define rel_evan_lab 1 "Evangelical" 0 "Other"
label value rel_evangelical rel_evan_lab

gen rel_catholic=1 if p66a==1
replace rel_catholic=0 if rel_catholic!=1 & rel_catholic!=.
label variable rel_catholic "Catholic (dummy 1 if catholic)"
label define rel_cath_lab 1 "Catholic" 0 "Other"
label value rel_catholic rel_cath_lab

gen rel_other=1 if p66a != 1 & p66a != 3 & p66a < 6
replace rel_other=. if p66a > 5
replace rel_other=0 if rel_other!=1 & rel_other!=.
label variable rel_other "Religious Other (dummy 1 if other)"
label define rel_other_lab 1 "Other" 0 "Evangelical/Catholic"
label value rel_other rel_other_lab

drop p66a

* no question about church attendance
* rename p6bb religiosity

label variable p68 "Age (years)"
rename p68 age
replace age = . if age == 99

rename p73 education
label variable education "Highest level of education"
replace education = . if education > 6

rename p70 val_abortion
label variable val_abortion "Opinion about abortion"
replace val_abortion = . if val_abortion > 10

rename p69 val_divorce
label variable val_divorce "Opinion about divorce"
replace val_divorce = . if val_divorce > 10

rename p28 eco_regulated
label variable eco_regulated "Regulate Economy"
label drop labels32
replace eco_regulated = . if eco_regulated > 5
replace eco_regulated = eco_regulated*2
* attention to the rescaling

rename p33 eco_tax
replace eco_tax=. if eco_tax > 2
label variable eco_tax "Whether legislator prefers direct or indirect taxes"
label define tax_lab 1 "direct" 2 "indirect"
label value eco_tax tax_lab                                                             

rename p2901 eco_prices
label variable eco_prices "Price control"
replace eco_prices =. if eco_prices > 4

rename p2902 eco_education_p
label variable eco_education_p "Free primary education"
replace eco_education_p = . if eco_education_p > 4
* combines primary and secondary education

rename p2907 eco_education_u 
label variable eco_education_u "Free university education"
replace eco_education_u = . if eco_education_u > 7
recode eco_education_u (1=1) (2=3) (3=5) (4=7)


rename p2903 eco_housing
label variable eco_housing "Subsidize housing"
replace eco_housing =. if eco_housing > 4

rename p2904 eco_employment
label variable eco_employment "Employment creation"
replace eco_employment = . if eco_employment > 7
recode eco_employment (1=1) (2=3) (3=5) (4=7)


rename p2906 eco_health
label variable eco_health "Whether the state should provide health services"
recode eco_health (1=1) (2=3) (3=5) (4=7)
replace eco_health = . if eco_health > 7

rename p2905 eco_pensions
label variable eco_pensions "Pension"
replace eco_pensions = . if eco_pensions > 7
recode eco_pensions (1=1) (2=3) (3=5) (4=7)


rename p35 eco_natural
label variable eco_natural "Natural resources"
replace eco_natural = . if eco_natural > 5

gen wave = 2

save "Peru_wave2.dta", replace
	
}
*****************************************************************
* Peru_2011_2016
*****************************************************************
{
*Calling the data 
 import spss using  ".\Peru\BASEDATOS_PERU_80.sav", clear
 
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 
 
 */
gen wave=3
drop legis 
gen legis = 2016

* Ideology 
replace ID1=. if  ID1>11
* Ideology Party
replace ID2=. if  ID2>11


// Attendance to church
gen church_attend=RE1b

gen regular=1 if RE1b==3 | RE1b==4 | RE1b==5
replace regular=0 if RE1b==1 | RE1b==2 

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "PER_UnidadNacional" if partido ==5 //
replace party = "PER_FIM" if partido ==6 //
replace party = "PER_PAP" if partido ==2 //
replace party = "PER_UPP" if partido ==1 //
replace party = "PER_AF" if partido ==3 //
replace party = "PER_PeruPosible" if partido ==4 //
replace party = "PER_Other" if partido ~=. & partido ~=1 & partido ~=2 & partido ~=3 & partido ~=6 & partido ~=6    

drop partido 

gen partido=party

*--------------------------
* Abortion
*--------------------------
replace VAL2 =. if VAL2>10
gen VAL2_2=VAL2
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221


*--------------------------
* SSM
*--------------------------
replace VAL1 =. if VAL1>10
gen val_ssm=VAL1
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1



*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if RE1==1
replace religious=0 if RE1==2
replace religious=. if RE1>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if RE1a==4
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if RE1a==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if RE1a~=1 & RE1a~=4 & religious==1 &  RE1a~=.
replace rel_other=0 if religious==1 & rel_catholic==1
replace rel_other=0 if religious==1 & rel_evangelical==1

*--------------------------
* Education
*--------------------------
gen education= SOCD7 if  SOCD7<9


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if SOCD4==2
replace female=0 if SOCD4==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=SOCD5 if SOCD5<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=EM1
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=ROES107 if  ROES107<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequaltiy=ROES104  if  ROES104<8

lab val eco_inequaltiy eco_education_u

*-----------------------
* State should create employment
*-----------------------
gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u

*-----------------------
* State companies
*-----------------------
gen eco_companies=ROES101    if  ROES101  <8

lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=ROES102     if  ROES102   <8

lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=ROES106      if  ROES106    <8

lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=ROES105       if  ROES105     <8

lab val eco_pensions eco_education_u

}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
//lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
//lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep wave nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm   eco_regulated education female age eco_inequaltiy eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_companies

}


*****************************************************************
* Save
***************************************************************** 
save "Peru_2011_2016.dta", replace
}
*****************************************************************

*****************************************************************
* Peru_2016_2021
*****************************************************************
{
clear
*Calling the data 2016_2021
 import spss using  ".\Peru\BASEDATOS_PERU_107.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 
 
 */
gen wave=4
drop legis 
gen legis = 2020

* Ideology 
replace ID1=. if  ID1>11
* Ideology Party
replace ID2=. if  ID2>11


// Attendance to church
gen church_attend=RE1b

gen regular=1 if RE1b==3 | RE1b==4 | RE1b==5
replace regular=0 if RE1b==1 | RE1b==2 

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "PER_APRA" if partido ==372 // 
replace party = "PER_AP" if partido ==375 //
replace party = "PER_FA" if partido ==386 //
replace party = "PER_PPK" if partido ==387 //
replace party = "PER_NP" if partido ==390 //
replace party = "PER_FP" if partido ==391 //

replace party = "PER_Other" if partido>391
drop partido 

gen partido=party

*--------------------------
* Abortion
*--------------------------
replace VAL2 =. if VAL2>10
gen VAL2_2=VAL2
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221

*--------------------------
* Immigration
*--------------------------
replace INM101 =. if INM101>6
gen val_imm=INM101
lab define VAL21 ///
	1 "Totally against" ///
	5 "Totally agree"
lab val val_imm VAL21

*--------------------------
* SSM
*--------------------------
replace VAL1 =. if VAL1>10
gen val_ssm=VAL1
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1

*--------------------------
* Drugs
*--------------------------
replace VAL3 =. if VAL3>10
gen val_drugs=VAL3

lab val val_drugs VAL1

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if RE1==1
replace religious=0 if RE1==2
replace religious=. if RE1>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if RE1a==17
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if RE1a==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=.

*--------------------------
* Education
*--------------------------
gen education= SOCD7 if  SOCD7<9


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if SOCD4==2
replace female=0 if SOCD4==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=SOCD5 if SOCD5<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=EM1
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=ROES107 if  ROES107<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequaltiy=ROES104  if  ROES104<8

lab val eco_inequaltiy eco_education_u

*-----------------------
* State should create employment
*-----------------------
gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u

*-----------------------
* State companies
*-----------------------
gen eco_companies=ROES101    if  ROES101  <8

lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=ROES102     if  ROES102   <8

lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=ROES106      if  ROES106    <8

lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=ROES105       if  ROES105     <8

lab val eco_pensions eco_education_u

}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep wave nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm val_drugs val_imm eco_regulated education female age eco_inequaltiy eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_companies

}


*****************************************************************
* Save
***************************************************************** 
save "Peru_2016_2021.dta", replace
}
*****************************************************************
* Append
***************************************************************** 
{
append using "Peru_2001_2006.dta"
append using "Peru_2011_2016.dta"
append using "Peru_wave2.dta", force

drop pais
gen pais = "Peru"
save "Peru_2001_2021.dta", replace
*****************************************************************
erase "Peru_2001_2006.dta"
erase "Peru_2011_2016.dta"
erase "Peru_2016_2021.dta"
erase "Peru_wave2.dta"

}
